//主页侧导航;
import HomeMenu from '../../config/menu';
//角色权限;
// import Roleper from '../../config/roleper';

//菜单；
let HomeMenus=  async ctx => {
    let res=await ctx.db.querys(`select viewpermissions from role where roleid='${ctx.info.roleid}'`);
    if(!res.length) return ctx.body={code:0,msg:'没有足够权限查看相应菜单'};
    let data=[];
    let rolemenu=JSON.parse(res[0].viewpermissions);
    rolemenu.forEach(item=>data.push(HomeMenu[item]));
    return ctx.body = {code: 1,msg: '相应菜单获取成功',data:data};
}

//角色权限;
let roleper =async ctx=>{
    let res=await ctx.db.querys(`select roleid from role`);
    if(!res.length) return ctx.body={code:0,msg:'暂无角色信息'};
    const data=res.length;
    return ctx.body = {code: 1,msg: '相应菜单获取成功',data: data};
}

export default{
    HomeMenus,roleper
}